package cn.element.io.bio.case2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

    public static void main(String[] args) {
        try {
            // 1.定义一个ServerSocket
            ServerSocket server = new ServerSocket(8848);

            // 2.监听客户端的Socket连接请求
            Socket socket = server.accept();

            // 3.从Socket中得到一个字节输入流
            InputStream is = socket.getInputStream();

            // 4.把字节输入流包装成缓冲字符流
            BufferedReader bis = new BufferedReader(new InputStreamReader(is));

            String l;
            while ((l = bis.readLine()) != null) {
                System.out.println("服务端接收到: " + l);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
